package util.com;

import com.alibaba.druid.pool.DruidDataSource;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

public class Alipool {
    static DruidDataSource dr;
    static {
        String fname = "druid.properties";
        InputStream file = Alipool.class.getClassLoader().getResourceAsStream(
                fname);
        Properties prop = new Properties();
        try {
            prop.load(file);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        // String name = prop.getProperty("username");
        // String pass = prop.getProperty("password");
        String driverClassName = prop.getProperty("driverClassName");
        String jdbcUrl = prop.getProperty("jdbcUrl");
        String username = prop.getProperty("username");
        String password = prop.getProperty("password");
        String initialSize = prop.getProperty("initialSize");
        String minIdle = prop.getProperty("minIdle");
        String maxActive = prop.getProperty("maxActive");
        String maxWait = prop.getProperty("maxWait");
        // System.out.println(name);
        // System.out.println(pass);
        System.out.println(driverClassName);
        System.out.println(jdbcUrl);
        System.out.println(username);
        System.out.println(password);
        System.out.println(initialSize);
        System.out.println(minIdle);
        System.out.println(maxActive);
        System.out.println(maxWait);
        // �������ӳ�

        dr = new DruidDataSource();
        dr.setDriverClassName(driverClassName);
        dr.setUrl(jdbcUrl);
        dr.setUsername(username);
        dr.setPassword(password);
        dr.setInitialSize(new Integer(initialSize));
        dr.setMaxActive(new Integer(maxActive));
        dr.setMinIdle(new Integer(minIdle));
        dr.setMaxWait(new Long(maxWait));

    }

    public static Connection getconn() {
        Connection conn = null;
        try {
            conn = dr.getConnection();

        } catch (SQLException e) {

            e.printStackTrace();
        }
        return conn;

    }
}
